package com.lesson3.singleton;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/8/27 10:01
 * 饿汉式写法
 */
public class Type1
{
    public static void main(String[] args)
    {
        Singleton1 instance = Singleton1.getInstance();
        Singleton1 instance1 = Singleton1.getInstance();
        System.out.println(instance.hashCode()==instance1.hashCode());
    }
}

class Singleton1{

    //1.本类内部创建一个对象实例
    private static final Singleton1 singleton1 = new Singleton1();

    //2.构造器私有化
    private Singleton1(){

    }

    public static Singleton1 getInstance(){
        return singleton1;
    }
}
